package xuli.service.impl;


import xuli.dao.ProductInfoDao;
import xuli.dao.impl.ProductInfoDaoImpl;
import entity.Product_Comment;
import util.PageUtil;
import xuli.dao.ProductCommentDao;
import xuli.dao.UserDao;
import xuli.dao.WareHouseProductDao;
import xuli.dao.impl.ProductCommentDaoImpl;
import xuli.dao.impl.UserDaoImpl;
import xuli.dao.impl.WareHouseProductDaoImpl;
import xuli.service.ProductCommentService;

import java.util.List;

/**
 * @author xuli
 */
public class ProductCommentServiceImpl implements ProductCommentService {
    private ProductCommentDao productCommentDao = new ProductCommentDaoImpl();
    private UserDao userDao = new UserDaoImpl();
    private ProductInfoDao productInfoDao = new ProductInfoDaoImpl();
    private WareHouseProductDao wareHouseProductDao = new WareHouseProductDaoImpl();

    @Override
    public List<Product_Comment> findByPages(PageUtil<Product_Comment> pageUtil, String productId) {
        List<Product_Comment> comments = productCommentDao.findByPages(pageUtil, productId);
        for (Product_Comment comment : comments) {
            comment.setProduct_info(productInfoDao.findProductById(Integer.parseInt(productId)));
            comment.setUser_inf(userDao.findById(comment.getUser_id()));
            comment.setWarehouse_product(wareHouseProductDao.findByIdAndModelId(productId,comment.getModel_id()));
        }
        return comments;
    }

    @Override
    public Integer getTotalCount(String productId) {
        return productCommentDao.getTotalCount(productId);
    }


}
